package com.ujcms.cms;

import org.owasp.html.HtmlPolicyBuilder;
import org.owasp.html.PolicyFactory;

public class FigureHtmlSanitizer {
    public static void main(String[] args) {
        // 创建一个自定义的策略配置
        PolicyFactory policy = new HtmlPolicyBuilder()
               .allowElements("figure")
               .allowElements("img")
               .allowAttributes("src", "alt").onElements("img")
               .toFactory();

        String inputHtml = "<figure><img src=\"https://cdn-images-1.medium.com/max/1024/1*JIY-WkvHT-xR_I1R0nryMw.png\" alt=\"\" /></figure>";
        // 使用自定义策略进行 HTML 净化
        String cleanHtml = policy.sanitize(inputHtml);

        System.out.println(cleanHtml);
    }
}